package com.ljh.utils;
import org.apache.commons.codec.digest.DigestUtils;


/**
 * @author ：刘剑鸿
 * @date ：Created in 2021/9/6 10:54
 * @description：MD5工具类
 * @modified By：
 * @version: $
 */
public class MD5Utils {
    public static String md5(String src){
        return DigestUtils.md5Hex(src);
    }
    /*准备盐*/
    private static final String salt = "1a2b3c4d";
    /*第一次加密*/
    public static String inputPassToFromPass(String inputPass){
        //盐
        String str =""+salt.charAt(0) + salt.charAt(2) + inputPass + salt.charAt(5) + salt.charAt(4);
        return md5(str);
    }


    /*第二次加密  后端转入数据库 */
    public static String fromPassToDBPass(String fromPass,String salt){
        String str = ""+ salt.charAt(0)+salt.charAt(2)+ fromPass + salt.charAt(5)+salt.charAt(4);
        return md5(str);
    }

    public static String inputPassToDBPass(String inputPass,String salt){
        String fromPass = inputPassToFromPass(inputPass);
        String dbPass = fromPassToDBPass(fromPass, salt);
        return dbPass;
    }
    public static void main(String[] args) {
        //从前端传过来的密码----》加密后 11031ffbf48e4ebd2a1a3ad618c63baa
        System.out.println(inputPassToFromPass("123456"));
        //d3b1294a61a07da9b49b6e22b2cbd7f9

        //b7797cce01b4b131b433b6acf4add449 存入数据库
        System.out.println(fromPassToDBPass("b7797cce01b4b131b433b6acf4add449","1a2b3c4d"));

        //b7797cce01b4b131b433b6acf4add449
        System.out.println(inputPassToDBPass("123456","1a2b3c4d"));

    }
}
